<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>{$meta_title}-狂雨小说CMS</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="__ADMIN__/css/admin.css"></head>
<body>
  <div class="layui-row">
    <div class="layui-col-md3">
      <div class="layui-card">
        <form class="layui-form" action="{:url('del',['id'=>$id])}">
        <div class="layui-card-header layui-chapter">
          <div class="layui-row">
            <div class="layui-col-md1 layui-chapter-checkbox"><input name="layTableCheckbox" lay-filter="layTableAllChoose" type="checkbox" lay-skin="primary"></div>
            <div class="layui-col-md11 layui-chapter-hr">
              <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit lay-filter="del" type="submit"><i class="layui-icon layui-icon-delete"></i> 删除</button>
              <span class="rf">共{:count($list)}章</span>
            </div>
          </div>
        </div>
        <div class="layui-card-body box-scroll">
          <ul class="layui-card-status">
            <li class="cur"><div class="layui-row"><div class="layui-col-md1 layui-chapter-checkbox"></div><div class="layui-col-md11"><h4>无标题</h4><p>0字</p></div></div></li>
            {volist name="list" id="vo"}
            <li>
              <div class="layui-row">
                <div class="layui-col-md1 layui-chapter-checkbox"><input name="key[]" type="checkbox" lay-skin="primary" value="{$key}"></div>
                <div class="layui-col-md11 ajax-get" url="{:url('chapter',['id'=>$id,'key'=>$key])}" callback="chapter_edit(data)">
                  <h4>{$vo['title']}</h4>
                  <p>{$vo['word']}字<span class="rf">{$vo['update_time']|time_format="m-d H:i"}</span></p>
                </div>
              </div>
              <a href="javascript:;" onclick="admin_del(this,'{:url('del',['id'=>$id,'key'=>$key])}','li')" class="layui-btn layui-btn-danger layui-btn-xs layuiadmin-reply">删除</a>
            </li>
            {/volist}
          </ul>
        </div>
        </form>
      </div>
    </div>
    <div class="layui-col-md9">
      <div class="layui-card layui-card-open">
        <div class="layui-card-body">
          <form class="layui-form" lay-filter="edit_chapter" action="{:url('edit')}">
            <div class="layui-form-item">
              <div class="layui-input-block">
                <input name="id" type="hidden" value="{$id}" />
                <input name="key" type="hidden" value="" />
                <input name="novel_id" type="hidden" value="{$Request.param.id}" />
                <button class="layui-btn layui-btn-normal" type="button" lay-filter="add_chapter"><i class="layui-icon layui-icon-add-1"></i>新建章节</button>
                <button class="layui-btn" type="button"  onclick="admin_show('导入章节','{:url('import',['novel_id'=>$Request.param.id,'id'=>$id])}',650,223,0)"><i class="layui-icon layui-icon-export"></i>导入章节</button>
                <div class="layui-btn-group rf">
                  <button class="layui-btn layui-btn-warm" lay-submit lay-filter="ajax" lay-data='{"issued":"0"}' callback="chapter_save(data)" type="submit">保存</button>
                  <button class="layui-btn" lay-submit lay-filter="ajax" lay-data='{"issued":"1"}' callback="chapter_save(data)" type="submit">发布</button>
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">章节名</label>
              <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" class="layui-input" value="">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">章节内容</label>
              <div class="layui-input-block">
                <textarea name="content" style="height: 500px;" lay-verify="required" class="layui-textarea"></textarea>
                <p class="setfont"><em>0</em> / 50000</p>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">作者的话</label>
              <div class="layui-input-block">
                <textarea name="intro" class="layui-textarea"></textarea>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
  <script type="text/javascript" src="__STATIC__/jquery/jquery.min.js"></script>
  <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js"></script>
  <script type="text/javascript" src="__ADMIN__/js/admin.js"></script>
  <script type="text/javascript">
    $(function() { 
      $('[name="content"]').keyup(function() { 
        var text = $(this).val();
        var counter = text.length;
        $(".setfont em").text(counter);
        $(".layui-card-status li.cur p").text(counter+"字");
      }); 
      $('[lay-filter="add_chapter"]').click(function(event) {
        $('.layui-card-status li').removeClass('cur');
        var html='<li class="cur"><div class="layui-row"><div class="layui-col-md1 layui-chapter-checkbox"></div><div class="layui-col-md11"><h4>无标题</h4><p>0字</p></div></div></li>';
        if($('.layui-card-status li h4:contains("无标题")').length<=0){
          $('.layui-card-status').prepend(html);
        }
        $('[lay-filter="edit_chapter"]')[0].reset();
      });
      $(document).on('click','div.ajax-get',function(){
        $('.layui-card-status li').removeClass('cur');
        $(this).parents('li').addClass('cur');
        layer.msg('加载中',{icon: 16});
        $('.layui-card-status li h4:contains("无标题")').parents('li').remove();
      });
    });
    function chapter_edit(data){
      form.val("edit_chapter",data.data);
      layer.close(layer.index);
    }

    function chapter_save(data){
      layer.msg(data.msg, {icon: 1,shade: 0.3,time: 2000},function(layero, index){
        if(data.data.issued==1){
          location.reload();
        }else{
          $('.layui-card-status li.cur').find('h4').text($('input[name="title"]').val());
          if(data.data.id){
            $('.layui-card-status li.cur').find('.layui-col-md11').addClass('ajax-get').attr("url",data.data.url).attr("callback","chapter_edit(data)");
            $('input[name="id"]').val(data.data.id);
          }
        }
      });
    }
  </script>
</body>
</html>